﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Web.Mvc;

using Lucene.Net.Documents;

using ERPStore.Extensions;
using ERPStore.Indexers.Lucene.Models;

namespace ERPStore.Indexers.Lucene.Workflows.Activities
{
	public sealed class CreateDocument : CodeActivity
	{
		// Define an activity input argument of type string
		public InArgument<ERPStore.Models.Product> Product { get; set; }
		public InArgument<int> RowCount { get; set; }

		public OutArgument<global::Lucene.Net.Documents.Document> Document { get; set; }

		protected override void Execute(CodeActivityContext context)
		{
			var product = context.GetValue(this.Product);
			var rowCount = context.GetValue(this.RowCount);

			var document = product.ToDocument();
			document.Add(new Field("RowCount", rowCount.ToString(), Field.Store.YES, Field.Index.NO));

			context.SetValue(Document, document);
		}
	}
}
